<?php
/* Exemple de résultat : 
l'etat correspond à une bonne réponse de l'utilisateur
<responses>
<list>
<item etat="true">abbesses,393,221</item>
<item etat="true">sèvres-babylone,328,502</item>
<item etat="false">bures-sur-yvette,201,584</item>
<item etat="false">chemin vert,513,435</item>
<item etat="false">porte de clignancourt,414,170</item>
<item etat="false">sucy bonneuil,578,454</item>
<item etat="false">corentin-cariou,573,202</item>
<item etat="false">félix faure,221,574</item>
<item etat="false">auguste delaune,732,159</item>
<item etat="false">mairie de saint-ouen,352,130</item>
</list>
</responses>*/

	header('Content-Type: text/xml');
	$bddRatp = fopen('../ressources/bddRatp.TXT', 'r');
	$fReponses = file_get_contents('../ressources/reponses.txt');	
	$reponses_tab = explode(':', $fReponses);
	$tableau = array();
	$trouver = false;

	$dom = new DOMDocument();
	$xml = $dom->createElement('responses');
	$list = $dom->createElement('list');
	$xml->appendChild($list);
	$dom->appendChild($xml);

	for ($i=0; $i < count($reponses_tab) - 1; $i++) {
		$temp_Tab = explode(',', $reponses_tab[$i]);
		$repUser = $temp_Tab[0];
		$id = $temp_Tab[1];
		$x =  $temp_Tab[2];
		$y =  $temp_Tab[3];
		while (($buffer = fgets($bddRatp)) !== false || $trouver !== true) {			
			$temp_Tab1 = explode(';', $buffer);
			if($id === $temp_Tab1[0]){				
				$item  = $dom->createElement('item');
				$attributeName = $dom->createAttribute('etat');
				$text = $dom->createTextNode($temp_Tab1[1].','.$x.','.$y);
	        	if($repUser === $temp_Tab1[1]){
	        		$attributeName->value = 'true';	        		
	        	}else{
	        		$attributeName->value = 'false';	        		
	        	}
	        	$item->appendChild($attributeName);
	        	$item->appendChild($text);
	        	$list->appendChild($item);	        	
	        	$trouver = true;
	        }	        
    	}
    	rewind($bddRatp);
    	$trouver = false;
	}
	$xmlString = $dom->saveXML();
    echo $xmlString;	
